package com.service.member.impl;

import com.bean.Member;
import com.dao.Mb_accountMapper;
import com.dao.MemberMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.service.core.AbstractService;
import com.service.member.MemberService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/10.
 */
@Service
public class MemberServiceImpl extends AbstractService<Member, Integer> implements MemberService {

    @Autowired
    private MemberMapper memberMapper;
    @Autowired
    private Mb_accountMapper mb_accountMapper;

    @Override
    public Member getMeberByTel(String tel) {
        return memberMapper.selectByTel(tel);
    }

    public Member getMeberByLoginName(String loginName) {
        return memberMapper.selectByLoginName(loginName);
    }
    @Override
    public Page findMembersByPage(int pageNum, int pageSize, HashMap<String, Object> paraMap) {
        PageHelper.startPage(pageNum, pageSize);
        Page page = (Page) memberMapper.findByParaMap(paraMap);
        return page;
    }

    @Override
    public Member getMemberByMerchantId(Integer id) {
        return memberMapper.selectByMerchantId(id);
    }

    @Override
    public int getInferiorsNumByLv(Integer mid, Integer lv,String startTime,String endTime) {
        HashMap<String, Object> paraMap=new HashMap<String, Object>();
        paraMap.put("mid",mid);
        paraMap.put("lv",lv);
        if(StringUtils.isNotBlank(startTime)){
            paraMap.put("startTime",startTime);
        }
        if(StringUtils.isNotBlank(endTime)){
            paraMap.put("endTime",endTime);
        }
        return memberMapper.getInferiorsNumByLv(paraMap);
    }

    @Override
    public Page findInferiorsByPage(int pageNum, int pageSize, HashMap<String, Object> paraMap) {
        PageHelper.startPage(pageNum,pageSize);
        Page page = (Page) memberMapper.findInferiors(paraMap);
        return page;
    }
    @Override
    public List<Map> countMember(HashMap<String, Object> paraMap) {
        return memberMapper.countMember(paraMap);
    }

    @Override
    public Member getMeberByOpenId(String openId) {

        return memberMapper.selectByOpenid(openId);

    }
}
